package kr.ragne.letsparissql;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;

public class LetsParisSqliteView extends View {
	private DBHelper mHelper;

	public LetsParisSqliteView(Context context) {
		super(context);
		mHelper = new DBHelper(context);
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		Paint p = new Paint();
		p.setTextSize(20);
		p.setColor(Color.BLACK);
		canvas.drawText("Ranking!!", 0, 20, p);
		canvas.drawText(" 순위  :  점수  :  날짜", 0, 40, p);
		//mHelper = new DBHelper(canvas);
		SQLiteDatabase db = mHelper.getReadableDatabase();
//		Cursor cursor = db.query("pari", new String[]{"_id","score","data"},null,null,null,null,"score desc");
		Cursor cursor = db.rawQuery("SELECT (SELECT COUNT(*)+1 FROM pari WHERE score > T.score) AS rank, score,data from pari as t order by rank asc", null);
		for(int i=0;i<10;i++){
			if(cursor.moveToNext() ==false)
				break;
			canvas.drawText("    " + cursor.getString(0) + "     :  " + cursor.getString(1)+" 초  : " + cursor.getString(2), 0, 60 + (20 * i), p);
		}
		db.close();
	}
}
